﻿using System.Configuration;
using System.Data;
using System.Windows;
using FlowNodeFramework.Views;

namespace FlowNodeFramework
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        protected override Window CreateShell()
        {
            return Container.Resolve<MainView>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            
        }

        protected override IModuleCatalog CreateModuleCatalog()
        {
            return new DirectoryModuleCatalog()
            {
                // 配置将在扫描的目录
                ModulePath = ".\\ModulePath"
            };
        }

        protected override void ConfigureViewModelLocator()
        {
            base.ConfigureViewModelLocator();
            ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver(TypeResolver);
        }

        private Type TypeResolver(Type view_type)
        {
            //PrismViewModelLocator.Views.MainWindow
            //PrismViewModelLocator.ViewModels.MainWindowViewModel

            // Prism自动关联ViewModel的默认规则：
            // View的类名称非View结尾的时候，解析ViewModel的类名称时候，后面需要加上ViewModel
            // View的类名称以View结尾的时候，解析ViewModel的类名称时候，后面只需要加上Model
            var vmName = view_type.FullName.Replace(".Views.", ".ViewModels.");
            if (vmName.EndsWith("View"))
                vmName += "Model";
            else
                vmName += "VM";

            return Type.GetType(vmName);
        }
    }
}
